package org.swingDemo.entity;

public class PageInfo {
    private int total;          // 总数
    private int pageSize;       // 每页最大显示数量
    private int totalPages;     // 总页数
    private int currentPage;    // 当前页

    public PageInfo(int total, int pageSize) {
        this.total = total;
        this.pageSize = pageSize;

        this.currentPage = 0;
        this.totalPages = (int) Math.ceil(1.0 * total / pageSize);
    }

    public void gotoFirst() {
        this.currentPage = 0;
    }

    public void gotoPrevious() {
        if (this.currentPage == 0) {
            return;
        }
        this.currentPage--;
    }

    public void gotoNext() {
        if (this.currentPage == this.totalPages - 1) {
            return;
        }
        this.currentPage++;
    }

    public void gotoLast() {
        this.currentPage = this.totalPages - 1;
    }

    public int getStart() {
        return this.currentPage * this.pageSize;
    }
}
